import sys
import re
import common
#if len(sys.argv)<2:
#     print("usage:")
#     exit(0)
#inf=sys.argv[1]
inf='dex-types.txt'

myfile = open(inf, "r")
bytes=[]
ll=[]
l=[]
for line in (myfile):
	if len(line)==0:
		continue
	if line.startswith('#'):
		continue
	s=line.strip(' \t\n')
	s1=s.split('\t',1)
	n=s1[0]
	if s1[1][0].isdigit():
		s2=s1[1].split(' ',1)
		bsize=s2[0]
		s3=s2[1]
	else:
		bsize='8-bit'
		s3=s1[1]
	s4=s3.rsplit(',',1)
	if len(s4)>1:
		comment=s4[1]
		s5=s4[0]
	else:
		comment=''
		s5=s3
		
	l=[n,bsize,s5,comment]
	#print(l)
	ll.append(l)
	
	
		
		
		
		

print('''
		
#ifndef dex_types_h
#define dex_types_h
#include <stdio.h>
#include "leb128.h"

typedef unsigned char ubyte;
typedef unsigned short ushort;
typedef unsigned int uint;

//typedef  char byte;


''')


for x in ll:
	print('//%s'%(x[3]))
	print('class %s\n{'%(common.get_cls_name(x[0])))
	s=x[2].split(' ',1)
	s1=s[0]
	if x[1][0]=='8':
		t=s1+' char'
		fmt='02'
	elif x[1][0]=='1':
		t=s1+' short'
		fmt='04'
	elif x[1][0]=='3':
		t=s1+' int'
		fmt='08'
	else:
		t=s1+' __int64'
		fmt='016'

	print('''
public:
	%s value;
'''%(t))
	
	if s[1]=='int':
		print('''
	void print() {printf("%%%sx",value);}
	int sprint( char *buffer) {return sprintf(buffer,"%%%sx",value);}
	int Size(){return sizeof(value);}
'''%(fmt,fmt))	
	else:	
		print('''
	void print() { print_leb128((const char *)&value);}
	int sprint( char *buffer) {return sprint_leb128(buffer,(const char *)&value);}
	int Size(){return size_leb128((const char *)&value);}
''')
		if x[0].endswith('p1'):
			print('\tint to_int(){return value_leb128((const char *)&value)-1;}')			
		else:
			print('\tint to_int(){return value_leb128((const char *)&value);}	')

			
	print('};')	
	
print('''
#endif//dex_types_h		
''')